package net.wanho.hospital.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.hospital.po.Doctor;
import net.wanho.hospital.po.Orders;
import net.wanho.hospital.service.DoctorUserService;
import net.wanho.hospital.service.OrdersService;
import net.wanho.hospital.service.PatientUserService;
import net.wanho.hospital.vo.AjaxResult;
import net.wanho.hospital.vo.DoctorVo;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-12-27
 */
@Api(tags = "接口")
@RestController
@RequestMapping("/doctor")
@RequiredArgsConstructor
public class DoctorUserController {

    private final DoctorUserService doctorUserService;
    private final OrdersService ordersService;
    private final PatientUserService patientUserService;

    @ApiOperation("分页查询")
    @GetMapping("/findDoctorBySectionPage")
    public AjaxResult findDoctorBySectionPage(
            @RequestParam("pageNumber")  int pageNum,
            @RequestParam("size")  int pageSize,
           @RequestParam("query") String dName,
           @RequestParam("dSection") String dSection,
           @RequestParam("arrangeDate") String arrangeDate){
        Map<String,Object> map = doctorUserService.findDoctorBySectionPage(pageNum, pageSize, dName, dSection, arrangeDate);
        return AjaxResult.success(map);
    }

    @ApiOperation("按主键查询")
    @GetMapping("/findPatientById")
    public AjaxResult getById(@ApiParam("学号") Integer pId){
        return AjaxResult.success(patientUserService.getById(pId));
    }

    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@RequestBody Doctor stu){
        doctorUserService.save(stu);
        return AjaxResult.success();
    }

    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@RequestBody Doctor doctor){
        doctorUserService.updateById(doctor);
        return AjaxResult.success();
    }

    @ApiOperation("按主键删除")
    @DeleteMapping("/{dId}")
    public AjaxResult removeById(@ApiParam("学号") @PathVariable Serializable dId){
        doctorUserService.removeById(dId);
        return AjaxResult.success();
    }

    @PostMapping("/login")
    public AjaxResult login(int dId, String dPassword){
        DoctorVo doctorVo = doctorUserService.login(dId, dPassword);
        return AjaxResult.success(doctorVo);
    }

    @GetMapping("/findOrderByNull")
    public AjaxResult findOrderByNull(Integer dId, String oStart){
        List<Orders> list = ordersService.findOrderByNull(dId, oStart);
        return AjaxResult.success(list);
    }

    @GetMapping("/updateStar")
    public AjaxResult updateStar(Integer dId, Integer dStar){
        doctorUserService.updateStar(dId, dStar);
        return AjaxResult.success();
    }

}
